package com.tcgroup.phone.base_core.binding.recycleview;


import androidx.databinding.BindingAdapter;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;


/**
 * Description: <ViewAdapter><br>
 * Author:      mxdl<br>
 * Date:        2019/7/4<br>
 * Version:     V1.0.0<br>
 * Update:     <br>
 */
public class ViewAdapter {

    @BindingAdapter({"linearLayoutManager"})
    public static void setLinearLayoutManager( RecyclerView recyclerView, boolean b) {
        LinearLayoutManager layoutManager = new LinearLayoutManager(recyclerView.getContext());
        layoutManager.setOrientation(b?LinearLayoutManager.HORIZONTAL:LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(layoutManager);
    }

    @BindingAdapter({"gridLayoutManager"})
    public static void setGridLayoutManager( RecyclerView recyclerView, int spanCount) {
        GridLayoutManager gridLayoutManager = new GridLayoutManager(recyclerView.getContext(),spanCount);
        recyclerView.setLayoutManager(gridLayoutManager);
    }
}
